package org.starsource.forum.server.domain;

import java.io.Serializable;
import java.sql.Timestamp;

import org.starsource.forum.client.util.Assertion;


public class LoginLog implements HasId, Serializable {
	
	protected static org.apache.log4j.Logger logger = org.apache.log4j.LogManager
	.getLogger(LoginLog.class.getName());

	private static final long serialVersionUID = 5309663523533166046L;

	private int id;
	
	private ForeignKey<User> user = new ForeignKey<User>();

	private String ip;

	private Timestamp timestamp;

	public LoginLog() {
		
	}
	
	public LoginLog(User user, String ip, Timestamp timestamp) {
		this.setUser(user);
		this.ip = ip;
		this.timestamp = timestamp;
	}
	
	public LoginLog(int id, User user, String ip, Timestamp timestamp) {
		this.id = id;
		this.setUser(user);
		this.ip = ip;
		this.timestamp = timestamp;
	}
	
	public boolean equals(Object obj) {
		try {
			LoginLog object = (LoginLog)obj;
			
			if (this.id != object.getId()) {
				logger.debug("this.id=" + this.id + " object.id=" + object.id);
				return false;
			}

			if (this.user.getId() != object.user.getId()) {
				logger.debug("this.userId=" + this.user.getId() + " object.userId=" + object.user.getId());
				return false;
			}
			if (!Assertion.isEqual(this.ip, object.ip)) {
				logger.debug("this.ip=" + this.ip + " object.ip=" + object.ip);
				return false;
			}
			if (!Assertion.isEqual(this.timestamp, object.timestamp)) {
				logger.debug("this.timestamp=" + this.timestamp + " object.timestamp=" + object.timestamp);
				return false;
			}

			return true;
		} catch (Exception e) {
			return false;
		}
	}
	
	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public Timestamp getTimestamp() {
		return timestamp;
	}

	public void setTimestamp(Timestamp timestamp) {
		this.timestamp = timestamp;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public User getUser() {
		return this.user.getObject();
	}
	
	public void setUser(User user) {
		this.user.setObject(user);
	}
	
	public int getUserId() {
		return this.user.getId();
	}
	
	public void setUserId(int userId) {
		this.user.setId(userId);
	}

}
